package com.wt.admin.service;

import cn.hutool.core.thread.ThreadUtil;
import com.wt.admin.config.aspect.LogAspect;
import com.wt.admin.config.socket.WebSocketSessionManager;
import com.wt.admin.domain.ConstVar;
import com.wt.admin.domain.vo.ProgressVO;
import com.wt.admin.domain.vo.SocketVO;
import com.wt.admin.service.file.FileService;
import com.wt.admin.service.sys.SysDataPermissionsService;
import com.wt.admin.service.sys.SysSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;

@Slf4j
@Component
public class InitService {

    @Resource
    private LogAspect logAspects;
    @Resource
    private FileService fileService;
    @Resource
    private SysSettingService sysSettingService;
    @Resource
    private SysDataPermissionsService sysDataPermissionsService;
    SocketVO<ProgressVO> initSocket = new SocketVO<>(ConstVar.Socket.PROGRESS, ProgressVO.set("欢迎登陆","callback", 0));

    @EventListener
    public void init(ApplicationReadyEvent event) {
        log.debug("Init Service Start");
        logAspects.init();
        fileService.init();
        sysSettingService.init();
        log.debug("Init Service End");
        ThreadUtil.sleep(20000);
        WebSocketSessionManager.sendToAll(initSocket.build(ProgressVO.set(50)));
        ThreadUtil.sleep(20000);
        WebSocketSessionManager.sendToAll(initSocket.build(ProgressVO.set(100)));
    }


}
